/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年2月25日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.lesson3.sort;

/**
 * @Type BobbleSort
 * @Desc
 * @author 52489
 * @date 2019年2月25日
 * @Version V1.0
 */
public class BobbleSort {
    int nums[] = { 2, 4, 3, 6, 1 };

    public void sort() {
        for (int i = 0; i < nums.length - 1; i++) {
            int mx = 0;
            for (int j = 0; j < nums.length - i - 1; j++) {
                if (nums[j] > nums[j + 1]) {
                    int tmp = nums[j + 1];
                    nums[j + 1] = nums[j];
                    nums[j] = tmp;
                }
                mx = nums[j + 1];
            }
            nums[nums.length - i - 1] = mx;
            int index = i + 1;
            System.out.print("第" + index + "次排序结果  ");
            for (int c : nums) {
                System.out.print(c + " ");

            }
            System.out.print("\n");

        }
    }

    public static void main(String[] args) {
        BobbleSort bobbleSort = new BobbleSort();
        bobbleSort.sort();
    }

}
